package com.ybwh.springboot1.dao;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Component;

import com.ybwh.springboot1.jdbc.BaseDao;
import com.ybwh.springboot1.model.po.Dict;
import com.ybwh.springboot1.model.po.WorkMessage;
import com.ybwh.springboot1.model.vo.DataTabelPageVo;

@Component
public class WorkMessageDao extends BaseDao {

	private static final String SELECT_RECORD_SQL = "select " + getEntityColumnSql(WorkMessage.class) + "  from "
			+ getEntityTableName(WorkMessage.class);
	private static final String SELECT_COUNT_SQL = "select count(*)  from " + getEntityTableName(WorkMessage.class);

	public DataTabelPageVo<WorkMessage> pageList(int start, int length, Map<String, Object> param) {
		List<Object> paramList = new ArrayList<>(3);
		StringBuilder whereSql = new StringBuilder(" where 1=1 ");
		if (null != param.get("employeeId")) {
			whereSql.append(" and employee_id = ? ");
			paramList.add(param.get("employeeId"));
		}

		Integer type = (Integer) param.get("type");
		if (null != type && 0 != type.intValue()) {

			whereSql.append(" and type >= ? and type< ?");
			paramList.add(10 * type.intValue());
			paramList.add(10 * (type.intValue() + 1));
		}

		if (null != param.get("pushChannel")) {
			whereSql.append(" and push_channel = ? ");
			paramList.add(param.get("pushChannel"));
		}

		whereSql.append(" order by id desc ");

		return queryDataTabelPageVo(start, length, SELECT_COUNT_SQL + whereSql.toString(),
				SELECT_RECORD_SQL + whereSql.toString(), WorkMessage.class, paramList);
	}

}
